package com.j01y.myhooks.Utils;

import android.app.Application;
import android.content.Context;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

public class HookHelpers {

    public static Context hookContext(XC_LoadPackage.LoadPackageParam lpparam){
        return (Context) XposedHelpers.callMethod(
                XposedHelpers.callStaticMethod(
                        XposedHelpers.findClass(
                                "android.app.ActivityThread",
                                lpparam.classLoader
                        ),
                        "currentActivityThread"
                ),
                "getSystemContext"
        );
    }
//    public static Context context(XC_LoadPackage.LoadPackageParam lpparam){
//        try {
//            XposedHelpers.findAndHookMethod(Application.class, "attach", Context.class, new XC_MethodHook() {
//                @Override
//                protected void afterHookedMethod(MethodHookParam param) throws Throwable {
//                    super.afterHookedMethod(param);
//                    Logger.logi(String.format("Get Needed Hook Package:%s", lpparam.packageName));
//                    Context appContext = (Context) param.args[0];
//                }
//            });
//        } catch (Exception e) {
//            Logger.loge(e.toString());
//        }
//    }
}
